﻿
@{
    Layout = null;
}

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="stylesheet" href="~/Content/bootstrap.min.css">
    <link rel="stylesheet" href="~/Content/login.css">

</head>
<body>

    <div class="container">
        <div class="row">
            <div class="col-sm">

            </div>
            <div class="col-sm">
                <div class="shadow-lg p-3 mb-5 rounded">


                    <div class="card">
                        <div class="card-header" style="font-size: 20px;">
                            请先登录
                        </div>
                        <div class="card-body">
                            <form id="loginForm">
                                <div class="form-group">
                                    <label for="exampleInputEmail1" style="font-size: 20px;">用户名：</label>
                                    <input type="" class="form-control" name="username" id="username"
                                           aria-describedby="emailHelp" style="background-color:rgba(0,0,0,0);">
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputPassword1" style="font-size: 20px;">密码：</label>
                                    <input type="password" class="form-control" name="password" id="password" style="background-color:rgba(0,0,0,0);">
                                </div>
                                <div class="form-group form-check">
                                    <input type="checkbox" class="form-check-input" id="exampleCheck1">
                                    <label class="form-check-label" for="exampleCheck1" style="font-size: 18px;">记住密码</label>
                                </div>
                                <div>
                                    <button type="button" class="btn btn-primary"
                                            onclick="dl()">
                                        登&nbsp;&nbsp;&nbsp;录
                                    </button>
                                    <button type="button" class="btn btn-primary"
                                            onclick="zc()">
                                        注&nbsp;&nbsp;&nbsp;册
                                    </button>
                                </div>

                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm">
            </div>
        </div>
    </div>


    <script src="~/Scripts/jquery-3.6.0.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>

    <script>
        function dl() {
            let username = $('#username').val();
            let password = $('#password').val();
            if (username.length > 0 && password.length > 0 ) {
                // ajax请求
                $.ajax({
                    url: "/users/loginDone",
                    type: "POST",
                    data: $('#loginForm').serialize(),
                    dataType: "json",
                    success: function (res) {
                        console.log(res);
                        if(res.code===200){
                            window.location.href="/";
                        }else{
                            console.log("1");
                            alert('用户名或密码错误！！');
                            alert('欸 还要点一次 气不气？？？？');

                        }

                    },
                    error: function (msg) {
                        alert('网络或者服务器有问题');
                    }
                })
            } else {// 验证不通过，提示相关信息，并且阻止提交
                alert('用户名和密码不能为空');
                return false;
            }
        }

        function zc() {
            window.location.href = '/users/register';
        }



    </script>

</body>

</html>
